import type { VxeGridProps } from '#/adapter/vxe-table'
import { EnumLogStatus, EnumLogType } from '#/config/enum/system'
import { logStatusOptions, logTypeOptions } from '#/config/options/system'
import { getOptionsLabelByValue } from '#/config/options/utils'
import { $t } from '@vben/locales'
import { unref } from 'vue'

// 列表表头
export const columns: VxeGridProps['columns'] = [
    {
        title: $t('page.system.children.log.children.form.title'),
        field: 'title',
        width: 120
    },
    {
        title: $t('page.system.children.log.children.form.logType'),
        field: 'logType',
        width: 120,
        cellRender: {
            name: 'Tag',
            props: {
                options: logTypeOptions,
                color(logType: EnumLogType) {
                    const arr = [
                        EnumLogType.删除,
                        EnumLogType.强退,
                        EnumLogType.设置状态,
                        EnumLogType.清空数据,
                        EnumLogType.修改
                    ]
                    return arr.includes(logType) ? 'red' : 'green'
                }
            }
        }
    },
    {
        title: $t('page.system.children.log.children.form.operationName'),
        field: 'operationName',
        width: 120
    },
    {
        title: $t('page.system.children.log.children.form.operationUrl'),
        field: 'operationUrl',
        width: 220
    },
    {
        title: $t('page.system.children.log.children.form.operationIp'),
        field: 'operationIp',
        width: 120
    },
    {
        title: $t('page.system.children.log.children.form.operationMethod'),
        field: 'operationMethod',
        width: 220
    },
    {
        title: $t('page.system.children.log.children.form.requestMethod'),
        field: 'requestMethod',
        width: 120
    },
    {
        title: $t('common.status'),
        field: 'status',
        width: 80,
        cellRender: {
            name: 'SwitchTag',
            props: {
                checkedChildren: getOptionsLabelByValue(EnumLogStatus.正常, logStatusOptions),
                uncheckedChildren: getOptionsLabelByValue(EnumLogStatus.异常, logStatusOptions),
                checkedValue: EnumLogStatus.正常,
                checkedColor: 'green',
                uncheckedColor: 'red'
            }
        }
    },
    {
        title: $t('page.system.children.log.children.form.spendTime'),
        field: 'spendTime',
        width: 120,
        cellRender: {
            name: 'CustomRender',
            props: {
                customRender: (value: number) => `${(value || 0) / 1000}s`
            }
        }
    },
    {
        title: $t('page.system.children.log.children.form.createTime'),
        field: 'createTime',
        width: 180
    },
    {
        field: 'action',
        fixed: 'right',
        slots: { default: 'action' },
        title: $t('common.action'),
        width: 90
    }
]

export const formSchema = [
    {
        fieldName: 'logType',
        label: $t('page.system.children.log.children.form.logType'),
        component: 'Select',
        componentProps: {
            options: unref(logTypeOptions)
        }
    },
    {
        fieldName: 'title',
        label: $t('page.system.children.log.children.form.title'),
        component: 'Input'
    },
    {
        fieldName: 'operationName',
        label: $t('page.system.children.log.children.form.operationName'),
        component: 'Input'
    }
]
